package com.organization.model.dao.impl

import com.organization.util.CustomHibernateDaoSupport
import com.organization.model.dao.EmployeeDao
import org.springframework.stereotype.Repository
import com.organization.model.Employee
import com.organization.model.Project

/**
 * Created with IntelliJ IDEA.
 * User: inester
 * Date: 10.07.12
 * Time: 13:27
 * To change this template use File | Settings | File Templates.
 */
@Repository("employeeDao")
class EmployeeDaoImpl extends CustomHibernateDaoSupport implements EmployeeDao {

    @Override
    public void save(Employee empl){
        getHibernateTemplate().save(empl);
    }

    @Override
    public void update(Employee empl){
        getHibernateTemplate().update(empl);
    }

    @Override
    public void delete(Employee empl){
        getHibernateTemplate().delete(empl);
    }

    @Override
    List<Employee> employeeList() {
        getHibernateTemplate().find("from Employee")
    }

    List<Employee> findAllByProject(Project proj){
        getHibernateTemplate().findByNamedParam("from Employee where project= :proj","proj",proj)
    }

    @Override
    Employee get(int id) {
        List<Employee> empls = getHibernateTemplate().findByNamedParam("from Employee where id = :emplId","emplId",id)
        return empls[0]
    }

}
